package 刷题.leedcode876;
//单指针法
public class Solution2 {
    //进行两次遍历
    //第一次遍历得到链表元素个数
    //第二次遍历到size/2的时候返回该元素
    public ListNode middleNode(ListNode head){
        int size = 0;
        ListNode cur = head;
        while(cur != null){
            ++size;
            cur = cur.next;
        }
        int n = 0;
        while(n < size/2){
            ++n;
            head = head.next;
        }
        return head;
    }
}
